import axios from "axios";
import base from "./base.js"


// 创建 axios 实例
const apiClient = axios.create({
	baseURL: base.url, // 设置基础 URL
	timeout: 10000, // 设置超时时间
	headers: {
		'Content-Type': 'application/json'
	}
});
//封装文件上传请求
export function upFile(url, filePath) {
	return uni.uploadFile({
		url: base.url + url,
		filePath: filePath,
		name: 'file',
		formData: {
			// 可以添加其他表单参数
			'x': 'additional-data'
		}
	});
}

// 封装 GET Params请求
export function getParams(url, data) {
	return apiClient.get(url, {
		params: data
	});
}
// 封装 GET 请求
export function getData(url) {
	return apiClient.get(url);
}

// 封装 POST 请求
export function postData(url, data) {
	return apiClient.post(url, data);
}

// 封装 POST Params请求
export function postParams(url, data) {
	return apiClient.post(url, {
		params: data
	});
}

// 封装 PUT 请求
export function updateData(url, data) {
	return apiClient.put(url, data);
}

// 封装 DELETE 请求
export function deleteData(url) {
	return apiClient.delete(url);
}

// 封装 DELETE Params请求
export function deleteParams(url,data) {
	return apiClient.delete(url,{
		params: data
	});
}